<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{$setting.webname} - 负责老师管理</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="/public/static/admin/layui/css/layui.css" rel="stylesheet">
    <link href="/public/static/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/public/static/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="/public/static/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="/public/static/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
    <style>
        #demo2 img{
            height: 110px;
        }
    </style>

</head>

<body class="gray-bg">
    <div class="row wrapper border-bottom white-bg page-heading">
        <div class="col-sm-4">
            <h2>负责老师管理</h2>
            <ol class="breadcrumb">
                <li>
                    <a href="{:url('Admins/admin')}">主页</a>
                </li>
                <li>
                    <strong>负责老师</strong>
                </li>
            </ol>
        </div>
    </div>
    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>修改负责老师</h5>
                    </div>

                    <div class="ibox-content">
                        <form class="form-horizontal" id="form1">
                            <!--姓名-->
                            <div class="form-group">
                                <label class="col-sm-2 control-label">姓名：</label>
                                <div class="col-sm-4">
                                    <input type="hidden" id="id" name="id" value="{$data.id}"/>
                                    <input type="text" placeholder="请输入姓名" id="name" name="name" value="{$data.name}" class="form-control"/>
                                </div>
                                <div class='col-sm-6'></div>
                            </div>
                            <!--性别-->
                            <div class="form-group">
                                <label class="col-sm-2 control-label">性别：</label>
                                <div class="col-sm-4">
                                    <div class="radio i-checks">
                                        <label style="padding-left:0px;"><input type="radio" name="sex" value="1" class="sex" checked>  男</label>
                                        <label style="padding-left:0px;"><input type="radio" name="sex" value="2" class="sex">  女</label>
                                    </div>
                                </div>
                                <div class='col-sm-6'></div>
                            </div>
                            <!--手机号-->
                            <div class="form-group">
                                <label class="col-sm-2 control-label">手机号：</label>
                                <div class="col-sm-4">
                                    <input type="text" placeholder="请输手机号" id="tel" name="tel" value="{$data.tel}" class="form-control">
                                </div>
                                <div class='col-sm-6'></div>
                            </div>
                            <!--格言-->
                            <div class="form-group">
                                <label class="col-sm-2 control-label">格言：</label>
                                <div class="col-sm-4">
                                    <input type="text" placeholder="请输格言" id="motto" name="motto" class="form-control" value="{$data.motto}">
                                </div>
                                <div class='col-sm-6'></div>
                            </div>
                            <!--头像-->
                            <div class="form-group">
                                <label class="col-sm-2 control-label">头像（本地上传）：</label>
                                <div class="col-sm-6">
                                    <input type="button" class="btn btn-success" value="已上传的二头像" id="selffile2">
                                    <button type="button" class="btn btn-info" id="test2">上传二头像</button>
                                    <div class="layui-upload-list">
                                        {if condition="preg_match('/base64/',$data.photo) > 0 "}
                                        <img class="layui-upload-img" id="demo2" style='width:auto;max-width:100%' src="{$data.photo}">
                                        {else /}
                                        <img class="layui-upload-img" id="demo2" style='width:auto;max-width:100%' src="/public/static/admin/uploads/teacher_photo/{$data.photo}">
                                        {/if}
                                        <p id="demoText2"></p>
                                    </div>
                                </div>
                                <div class='col-sm-4'></div>
                            </div>
                            <!--微信二维码-->
                            <div class="form-group">
                                <label class="col-sm-2 control-label">微信二维码（本地上传）：</label>
                                <div class="col-sm-6">
                                    <input type="button" class="btn btn-success" value="已上传的二维码" id="selffile">
                                    <button type="button" class="btn btn-info" id="test1">上传二维码</button>
                                    <div class="layui-upload-list">
                                        <img class="layui-upload-img" id="demo1" style='width:auto;max-width:100%' src="/public/static/admin/uploads/teacher_qr/{$data.wx_qrcode}">
                                        <p id="demoText"></p>
                                    </div>
                                </div>
                                <div class='col-sm-4'></div>
                            </div>
                            <!--所属小组-->
                            <div class="form-group">
                                <label class="col-sm-2 control-label">所属小组：</label>
                                <div class="col-sm-4">
                                    <select class="form-control m-b" name="pid" id="pid">
                                        <option value="0">自己</option>
                                        {foreach $teacher as $val}
                                        <option value="{$val.id}">{$val.name}</option>
                                        {/foreach}
                                    </select>
                                </div>
                                <div class='col-sm-6'></div>
                            </div>
                            <!--是否可以点名-->
                            <div class="form-group">
                                <label class="col-sm-2 control-label">是否可以点名：</label>
                                <div class="col-sm-4">
                                    <select class="form-control m-b" name="is_attendances" id="is_attendances">
                                        <option value="1">可以</option>
                                        <option value="2">不可以</option>
                                    </select>
                                </div>
                                <div class='col-sm-6'></div>
                            </div>
                            <!--状态-->
                            <div class="form-group">
                                <label class="col-sm-2 control-label">状态：</label>
                                <div class="col-sm-4">
                                    <select class="form-control m-b" name="status" id="status">
                                        <option value="1">显示</option>
                                        <option value="2">不显示</option>
                                    </select>
                                </div>
                                <div class='col-sm-6'></div>
                            </div>
                            <!--分享的易企秀的地址-->
                            <div class="form-group">
                                <label class="col-sm-2 control-label">分享地址：</label>
                                <div class="col-sm-4">
                                    <input type="text" placeholder="请输入分享地址" id="adv_href" name="adv_href" value="{$data.adv_href}" class="form-control">
                                    <span>分享易企秀的地址。</span>
                                </div>
                                <div class='col-sm-6'></div>
                            </div>
                            <!--分享易企秀的地址到盆友圈时的分享文案-->
                            <div class="form-group">
                                <label class="col-sm-2 control-label">分享时的文案：</label>
                                <div class="col-sm-4">
                                    <textarea type="text" placeholder="请输入分享文案" id="adv_str" name="adv_str" class="form-control">{$data.adv_str}</textarea>
                                    <span>分享易企秀的地址到盆友圈时的分享文案。</span>
                                </div>
                                <div class='col-sm-6'></div>
                            </div>
                            <!--确认-->
                            <div class="form-group">
                                <label class="col-sm-2 control-label"></label>
                                <div class="col-sm-4">
                                    <button type="button" class="btn btn-info btn-sm btn-block" id="save"> 保存修改</button>
                                </div>
                                <div class='col-sm-6'></div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div> 
    </div>
    <style>
        .layer_notive,
        .layer_notive2{
            width: 700px;
            margin: 20px auto;
            min-height: 500px;
            display: none;
        }
        .layer_notive ul li,
        .layer_notive2 ul li{
            float:left;
            margin:5px;
            width: 200px;
            position: relative;
            overflow: hidden;
            z-index: 9;

        }
        .layer_notive ul li img,
        .layer_notive2 ul li img{
            max-width: 100%;
            padding:1px;
            border:2px solid #ccc;
            opacity: 0.7;
        }
        .active,
        .active2{
            border:2px solid green!important;
            opacity: 1!important;
        }
        .del_div,
        .del_div2{
            position: absolute;
            top: -4px;
            text-align: center;
            line-height: 20px;
            right: -20px;
            width: 60px;
            height: 30px;
            background: rgb(219 219 219);
            transform: rotateZ(45deg);
            z-index: 8;
        }
        .del,
        .del2{
            color: #000;
            position: absolute;
            top: 13px;
            left: 23px;
            transform: rotate(-45deg);
        }
    </style>
    <!--弹出已上传的图片-->
    <div class="layer_notive" >
        <ul id="imglist"></ul>
        <div style="clear:both"></div>
    </div>
    <!--弹出头像窗口-->
    <div class="layer_notive2" >
        <ul id="imglist2"></ul>
        <div style="clear:both"></div>
    </div>
    <!-- 全局js -->
    <script src="/public/static/admin/layui/layui.js"></script>
    <script src="/public/static/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/public/static/admin/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- 自定义js -->
    <script src="/public/static/admin/js/content.js?v=1.0.0"></script>
    <script src="/public/static/admin/js/plugins/prettyfile/bootstrap-prettyfile.js"></script>


    <script src="/public/static/admin/js/plugins/iCheck/icheck.min.js"></script>
    <script>
        var photo = '{$data.wx_qrcode}';
        var teacher_photo = '{$data.photo}'
        //单选和复选框
        $(document).ready(function () {
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
        });
        //默认选项
        $(".sex[value='{$data.sex}']").prop("checked",true);
        $("#status option[value='{$data.status}']").prop("selected",true);
        $("#is_attendances option[value='{$data.is_attendances}']").prop("selected",true);
        $("#pid option[value='{$data.pid}']").prop("selected",true);
        layui.use('upload', function() { //独立版的layer无需执行这一句
            var $ = layui.jquery, layer = layui.layer,upload = layui.upload; //独立版的layer无需执行这一句
            $("#save").click(function(){
                var data = {};
                data['id'] = $("#id").val();
                $("#form1").serializeArray().forEach(h=>{
                    data[h.name] = h.value;
                });
                data['wx_qrcode'] = photo;
                data['photo'] = teacher_photo
                //修改
                //判断数据是否完整
                if($("#name").val() == ""){
                    top.layer.msg("请输入姓名",{time:2000,shade:0.5});
                    $("#name").focus();
                }else{
                    if(/^1[3,5,6,7,8,9]\d{9}$/.test($("#tel").val())){
                        $.post("{:url('Teachers/toUpdate')}",data,function(data){
                            top.layer.msg(data.msg,{time:2000,shade:0.5},function(){
                                if(data.url){
                                    window.location.href = data.url;
                                }
                            });
                        });
                    }else{
                        top.layer.msg("请输入正确的手机号",{time:2000,shade:0.5});
                        $("#tel").focus();
                    }
                }
            });

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#test1'
                ,url: "{:url('Teachers/upload')}"
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        $('#demo1').attr('src', result); //图片链接（base64）
                    });
                }
                ,done: function(res){
                    //如果上传失败
                    if(res.code == 0){
                        return top.layer.msg('上传失败',{shade:0.5});
                    }else if(res.code){
                        //上传成功
                        // photo = "/public/static/admin/uploads/teacher_qr/"+res.photo;
                        photo = res.photo;
                        return top.layer.msg('上传成功',{shade:0.5});
                    }
                }
                ,error: function(){
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function(){
                        uploadInst.upload();
                    });
                }
            });

            //显示本地图片
            $("#selffile").click(function () {
                $.post("{:url('Base/getmyfiles')}",{path:"/public/static/admin/uploads/teacher_qr"},function(data){
                    console.log(data);
                    var str = "";
                    for( i in data.msg){
                        str += "<li><img src='/public/static/admin/uploads/teacher_qr/"+data.msg[i]+"' class='imglist' data-photo='"+data.msg[i]+"' onclick='changecss(this)' alt=''><div class='del_div'><i class='fa fa-close del' title='删除' data-path='/public/static/admin/uploads/teacher_qr/"+data.msg[i]+"'></i></div></li>";
                    }
                    $("#imglist").html(str);
                    //页面层
                    layer.open({
                        type: 1,
                        skin: false, //加上边框
                        title: "已上传的图片",
                        area: ['710px', '600px'], //宽高
                        btn:["确认","取消"],
                        content: $(".layer_notive"),  //调到新增页面
                        yes:function(){
                            var newImgsrc = $(".active").attr("src");
                            var newImgname = $(".active").data("photo");
                            $('#demo1').attr('src', newImgsrc); //图片链接（base64）
                            $('#demo1').attr('width','100%');
                            photo = newImgname;
                            layer.closeAll();
                        }
                    });
                });
            });
            //删除图片
            $("#imglist").on("click",".del",function(v){
               $this = $(this);

                //页面层
                top.layer.msg('你确定要删除这张图片吗?', {
                    time: 20000, //20s后自动关闭
                    shade:0.5,
                    btn: ['确定', '取消'],
                    yes:function(){
                        var data  = {
                            "path" : $this.data("path")
                        }
                        $.post("{:url('Base/delfile')}",data,function(data){
                            top.layer.msg(data.msg,{time:2000,shade:0.5},function(){
                                $.post("{:url('Base/getmyfiles')}",{path:"/public/static/admin/uploads/teacher_qr"},function(data) {
                                    console.log(data);
                                    var str = "";
                                    for (i in data.msg) {
                                        str += "<li><img src='/public/static/admin/uploads/teacher_qr/" + data.msg[i] + "' class='imglist' data-photo='" + data.msg[i] + "' onclick='changecss(this)' alt=''><div class='del_div'><i class='fa fa-close del' title='删除' data-path='/public/static/admin/uploads/teacher_qr/" + data.msg[i] + "'></i></div></li>";
                                    }
                                    $("#imglist").html(str);
                                });
                            });
                        });
                    }
                });
            });

            //头像
            //普通图片上传
            var uploadInsts = upload.render({
                elem: '#test2'
                ,url: "{:url('Teachers/upload_photo')}"
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        $('#demo2').attr('src', result); //图片链接（base64）
                    });
                }
                ,done: function(res){
                    //如果上传失败
                    if(res.code == 0){
                        return top.layer.msg('上传失败',{shade:0.5});
                    }else if(res.code){
                        //上传成功
                        // photo = "/public/static/admin/uploads/teacher_qr/"+res.photo;
                        teacher_photo = res.photo;
                        return top.layer.msg('上传成功',{shade:0.5});
                    }
                }
                ,error: function(){
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText2');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function(){
                        uploadInsts.upload();
                    });
                }
            });

            //显示本地图片
            $("#selffile2").click(function () {
                $.post("{:url('Base/getmyfiles')}",{path:"/public/static/admin/uploads/teacher_photo"},function(data){
                    console.log(data);
                    var str = "";
                    for( i in data.msg){
                        str += "<li><img src='/public/static/admin/uploads/teacher_photo/"+data.msg[i]+"' class='imglist2' data-photo='"+data.msg[i]+"' onclick='changecss2(this)' alt=''><div class='del_div2'><i class='fa fa-close del2' title='删除' data-path='/public/static/admin/uploads/teacher_photo/"+data.msg[i]+"'></i></div></li>";
                    }
                    $("#imglist2").html(str);
                    //页面层
                    layer.open({
                        type: 1,
                        skin: false, //加上边框
                        title: "已上传的图片",
                        area: ['710px', '600px'], //宽高
                        btn:["确认","取消"],
                        content: $(".layer_notive2"),  //调到新增页面
                        yes:function(){
                            var newImgsrc = $(".active2").attr("src");
                            var newImgname = $(".active2").data("photo");
                            $('#demo2').attr('src', newImgsrc); //图片链接（base64）
                            $('#demo2').attr('width','100%');
                            teacher_photo = newImgname;
                            layer.closeAll();
                        }
                    });
                });
            });
            //删除图片
            $("#imglist2").on("click",".del2",function(v){
                $this = $(this);
                //页面层
                top.layer.msg('你确定要删除这张图片吗?', {
                    time: 20000, //20s后自动关闭
                    shade:0.5,
                    btn: ['确定', '取消'],
                    yes:function(){
                        var data  = {
                            "path" : $this.data("path")
                        }
                        $.post("{:url('Base/delfile')}",data,function(data){
                            top.layer.msg(data.msg,{time:2000,shade:0.5},function(){
                                $.post("{:url('Base/getmyfiles')}",{path:"/public/static/admin/uploads/teacher_photo"},function(data) {
                                    console.log(data);
                                    var str = "";
                                    for (i in data.msg) {
                                        str += "<li><img src='/public/static/admin/uploads/teacher_photo/" + data.msg[i] + "' class='imglist2' data-photo='" + data.msg[i] + "' onclick='changecss2(this)' alt=''><div class='del_div2'><i class='fa fa-close del2' title='删除' data-path='/public/static/admin/uploads/teacher_photo/" + data.msg[i] + "'></i></div></li>";
                                    }
                                    $("#imglist2").html(str);
                                });
                            });
                        });
                    }
                });
            });

        });
        //点击图片选择图片
        function changecss(obj){
            $(".imglist").removeClass("active");
            $(obj).addClass("active");
        }

        //点击图片选择图片
        function changecss2(obj){
            $(".imglist2").removeClass("active");
            $(obj).addClass("active2");
        }

    </script>

  </body>
</html>
